unit frmDownFile;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, SHDocVw, uWorkbench, frmPlaybackItem, StdCtrls, Buttons,
  uDelphiBaseForm, uLangConst;

type
  TDownFileForm = class(TDelphiBaseForm)
    pnlDownFile: TPanel;
    scrlbxCourseList: TScrollBox;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    wbDownFile: TWebBrowser;
    FWorkbench: IMMWorkbench;
  public
    procedure SetWorkbench(AWorkbench: IMMWorkbench);
    procedure RefreshCourseList();
    procedure ChangeLanguage(ALanguageIniFile: string); override;
  end;

implementation

{$R *.dfm}


procedure TDownFileForm.ChangeLanguage(ALanguageIniFile: string);
begin
  inherited ChangeLanguage(ALanguageIniFile);
end;

procedure TDownFileForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caHide;
end;

procedure TDownFileForm.FormCreate(Sender: TObject);
begin
  wbDownFile := TWebBrowser.Create(nil);
  FWorkbench := nil;
end;

procedure TDownFileForm.FormDestroy(Sender: TObject);
begin
  wbDownFile.Free;
end;

procedure TDownFileForm.FormShow(Sender: TObject);
begin
  RefreshCourseList();
  TranslateConsts(getLanguageFileName());
  ChangeLanguage(getLanguageFileName());
end;

procedure TDownFileForm.RefreshCourseList;
var
  Res: string;
  ls: TStringList;
  iLoop: Integer;
begin
  scrlbxCourseList.DisableAlign;
  scrlbxCourseList.DestroyComponents;
  Res := FWorkbench.GetCourseList();
  if Length(Res) > 0 then
  begin
    ls := TStringList.Create;
    try
      ls.Delimiter := '|';
      ls.DelimitedText := Res;
      for iLoop := 0 to ls.Count - 1 do
      begin
        PlayBackItemForm := TPlayBackItemForm.Create(nil);
        scrlbxCourseList.InsertComponent(PlayBackItemForm);
        PlayBackItemForm.Parent := scrlbxCourseList;
        PlayBackItemForm.Align := alTop;
        PlayBackItemForm.Caption := ls.Strings[iLoop];
        PlayBackItemForm.SetWorkbench(FWorkbench);
        PlayBackItemForm.Show;
      end;
    finally
      ls.Free;
    end;
  end;
  scrlbxCourseList.EnableAlign;
  Self.Height := Self.Height + 1;
end;

procedure TDownFileForm.SetWorkbench(AWorkbench: IMMWorkbench);
begin
  FWorkbench := AWorkbench;
end;

end.
